<?php

/*------------------------------------------------
*
*   Explay Engine Content Management System.
*   Copyright © 2008 Golovdinov Alexander.
*
*-------------------------------------------------
*
*   Official site: wwww.alex-home.spb.ru/explay.html
*   Contact e-mail: golovdinov@gmail.com
*
*   GNU General Public License original source:
*   http://www.gnu.org/licenses/gpl-3.0.html
*
------------------------------------------------*/

if (!defined ('EXPLAY')) exit;


if (file_exists ($_SERVER['DOCUMENT_ROOT'].'/include/cache/menu.html'))
	$content = file_get_contents ($_SERVER['DOCUMENT_ROOT'].'/include/cache/menu.html');
else {
	$content = build_menu ();
	cache_file ('menu.html', $content);
}

CORE::body_replace ($replace, $content);





function build_menu () {
	global $db;
	
	$content = '';
	
	$get_menu = $db->query ("SELECT link_group, link_text, link_url, link_target FROM ".DB_PEREFIX."_menu ORDER BY link_pos");
	
	if (is_registered()) {	
		while (list($group, $text, $link, $target) = $db->fetch_row ($get_menu)) {
			$menu = get_element('{menu}', '{/menu}');
			$menu = str_replace ('{LINK}', $link, $menu);
			$menu = str_replace ('{TARGET}', $target, $menu);
			$menu = str_replace ('{TEXT}', $text, $menu);
			$content .= $menu;
		}
	} else {
		while (list($group, $text, $link, $target) = $db->fetch_row ($get_menu)) {
			if ($group != 'register') {
				$menu = get_element('{menu}', '{/menu}');
				$menu = str_replace ('{LINK}', $link, $menu);
				$menu = str_replace ('{TARGET}', $target, $menu);
				$menu = str_replace ('{TEXT}', $text, $menu);
				$content .= $menu;
			}
		}
	}
	
	return $content;
}


